Avoid logic duplication
authorDavid Davidović <geosoft.corp@gmail.com>
Wed, 24 Dec 2014 20:37:01 +0000 (21:37 +0100)
committerDavid Davidović <geosoft.corp@gmail.com>
Wed, 24 Dec 2014 20:37:01 +0000 (21:37 +0100)
As suggested by @alexcrichton, reverted back to the old way of handling
both Job::new and Job::noop that avoids ugly constructs and code
duplication

src/cargo/ops/cargo_rustc/mod.rs

index fb61306e65565905554dc8b103c069be1d30ec4c..5029b8a6b7c02ac60f04f9ad0af071af34d4f2fc 100644 (file)
@@ -201,6 +201,12 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package,
     // a real job. Packages which are *not* compiled still have their jobs
     // executed, but only if the work is fresh. This is to preserve their
     // artifacts if any exist.
+    let job = if compiled {
+        Job::new as fn(Work, Work) -> Job
+    } else {
+        Job::noop as fn(Work, Work) -> Job
+    };
+
     if !compiled { jobs.ignore(pkg); }
 
     if targets.is_empty() {
@@ -252,8 +258,7 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package,
                 try!(work.call(desc_tx.clone()));
                 dirty.call(desc_tx)
             });
-            dst.push((if compiled { Job::new(dirty, fresh) } 
-                      else { Job::noop(dirty, fresh) }, freshness));
+            dst.push((job(dirty, fresh), freshness));
         }
 
         // If this is a custom build command, we need to not only build the
@@ -290,8 +295,7 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package,
                 }
             let (dirty, fresh, freshness) =
                 try!(custom_build::prepare(pkg, target, req, cx));
-            run_custom.push((if compiled { Job::new(dirty, fresh) } 
-                             else { Job::noop(dirty, fresh) }, freshness));
+            run_custom.push((job(dirty, fresh), freshness));
         }
 
         // If no build scripts were run, no need to compile the build script!
@@ -330,8 +334,7 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package,
             dirty.call(desc_tx)
         });
         jobs.enqueue(pkg, Stage::BuildCustomBuild, vec![]);
-        jobs.enqueue(pkg, Stage::RunCustomBuild, vec![(if compiled { Job::new(dirty, fresh) } 
-                           else { Job::noop(dirty, fresh) }, freshness)]);
+        jobs.enqueue(pkg, Stage::RunCustomBuild, vec![(job(dirty, fresh), freshness)]);
     }
 
     jobs.enqueue(pkg, Stage::Libraries, libs);